<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Eigen: $title</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="eigendoxy.css" rel="stylesheet" type="text/css">
<!--  -->
<script type="text/javascript" src="eigen_navtree_hacks.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="Eigen_Silly_Professor_64x64.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname"><a href="http://eigen.tuxfamily.org">Eigen</a>
   &#160;<span id="projectnumber">3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)</span>
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.svg"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('TutorialSparse_example_details.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="contents">
<div class="textblock"><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;Eigen/Sparse&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;QImage&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">typedef</span> <a class="code" href="classEigen_1_1SparseMatrix.html">Eigen::SparseMatrix&lt;double&gt;</a> SpMat; <span class="comment">// declares a column-major sparse matrix type of double</span></div>
<div class="line"><span class="keyword">typedef</span> <a class="code" href="classEigen_1_1Triplet.html">Eigen::Triplet&lt;double&gt;</a> T;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> insertCoefficient(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, <span class="keywordtype">int</span> i, <span class="keywordtype">int</span> j, <span class="keywordtype">double</span> w, std::vector&lt;T&gt;&amp; coeffs,</div>
<div class="line">                       <a class="code" href="classEigen_1_1Matrix.html">Eigen::VectorXd</a>&amp; b, <span class="keyword">const</span> <a class="code" href="classEigen_1_1Matrix.html">Eigen::VectorXd</a>&amp; boundary)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordtype">int</span> n = int(boundary.<a class="code" href="classEigen_1_1DenseCoeffsBase_3_01Derived_00_01DirectWriteAccessors_01_4.html#ae106171b6fefd3f7af108a8283de36c9">size</a>());</div>
<div class="line">  <span class="keywordtype">int</span> id1 = i+j*n;</div>
<div class="line"> </div>
<div class="line">        <span class="keywordflow">if</span>(i==-1 || i==n) b(<span class="keywordtype">id</span>) -= w * boundary(j); <span class="comment">// constrained coefficient</span></div>
<div class="line">  <span class="keywordflow">else</span>  <span class="keywordflow">if</span>(j==-1 || j==n) b(<span class="keywordtype">id</span>) -= w * boundary(i); <span class="comment">// constrained coefficient</span></div>
<div class="line">  <span class="keywordflow">else</span>  coeffs.push_back(T(<span class="keywordtype">id</span>,id1,w));              <span class="comment">// unknown coefficient</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> buildProblem(std::vector&lt;T&gt;&amp; coefficients, <a class="code" href="classEigen_1_1Matrix.html">Eigen::VectorXd</a>&amp; b, <span class="keywordtype">int</span> n)</div>
<div class="line">{</div>
<div class="line">  b.<a class="code" href="classEigen_1_1PlainObjectBase.html#acc39eaf7ba22b725c86f1b9b8bb57c3c">setZero</a>();</div>
<div class="line">  <a class="code" href="classEigen_1_1Array.html">Eigen::ArrayXd</a> boundary = <a class="code" href="classEigen_1_1DenseBase.html#a1c6d1dbfeb9f6491173a83eb44e14c1d">Eigen::ArrayXd::LinSpaced</a>(n, 0,M_PI).sin().pow(2);</div>
<div class="line">  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j=0; j&lt;n; ++j)</div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;n; ++i)</div>
<div class="line">    {</div>
<div class="line">      <span class="keywordtype">int</span> <span class="keywordtype">id</span> = i+j*n;</div>
<div class="line">      insertCoefficient(<span class="keywordtype">id</span>, i-1,j, -1, coefficients, b, boundary);</div>
<div class="line">      insertCoefficient(<span class="keywordtype">id</span>, i+1,j, -1, coefficients, b, boundary);</div>
<div class="line">      insertCoefficient(<span class="keywordtype">id</span>, i,j-1, -1, coefficients, b, boundary);</div>
<div class="line">      insertCoefficient(<span class="keywordtype">id</span>, i,j+1, -1, coefficients, b, boundary);</div>
<div class="line">      insertCoefficient(<span class="keywordtype">id</span>, i,j,    4, coefficients, b, boundary);</div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> saveAsBitmap(<span class="keyword">const</span> <a class="code" href="classEigen_1_1Matrix.html">Eigen::VectorXd</a>&amp; x, <span class="keywordtype">int</span> n, <span class="keyword">const</span> <span class="keywordtype">char</span>* filename)</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="classEigen_1_1Array.html">Eigen::Array&lt;unsigned char,Eigen::Dynamic,Eigen::Dynamic&gt;</a> bits = (x*255).cast&lt;unsigned char&gt;();</div>
<div class="line">  QImage img(bits.<a class="code" href="classEigen_1_1PlainObjectBase.html#ac54123f62de4c46a9107ff53890b6116">data</a>(), n,n,QImage::Format_Indexed8);</div>
<div class="line">  img.setColorCount(256);</div>
<div class="line">  <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;256;i++) img.setColor(i,qRgb(i,i,i));</div>
<div class="line">  img.save(filename);</div>
<div class="line">}</div>
<div class="ttc" id="aclassEigen_1_1Array_html"><div class="ttname"><a href="classEigen_1_1Array.html">Eigen::Array</a></div><div class="ttdoc">General-purpose arrays with easy API for coefficient-wise operations.</div><div class="ttdef"><b>Definition:</b> Array.h:49</div></div>
<div class="ttc" id="aclassEigen_1_1DenseBase_html_a1c6d1dbfeb9f6491173a83eb44e14c1d"><div class="ttname"><a href="classEigen_1_1DenseBase.html#a1c6d1dbfeb9f6491173a83eb44e14c1d">Eigen::DenseBase::LinSpaced</a></div><div class="ttdeci">static EIGEN_DEPRECATED const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &amp;low, const Scalar &amp;high)</div><div class="ttdef"><b>Definition:</b> CwiseNullaryOp.h:246</div></div>
<div class="ttc" id="aclassEigen_1_1DenseCoeffsBase_3_01Derived_00_01DirectWriteAccessors_01_4_html_ae106171b6fefd3f7af108a8283de36c9"><div class="ttname"><a href="classEigen_1_1DenseCoeffsBase_3_01Derived_00_01DirectWriteAccessors_01_4.html#ae106171b6fefd3f7af108a8283de36c9">Eigen::DenseCoeffsBase&lt; Derived, DirectWriteAccessors &gt;::size</a></div><div class="ttdeci">EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT</div><div class="ttdef"><b>Definition:</b> EigenBase.h:69</div></div>
<div class="ttc" id="aclassEigen_1_1Matrix_html"><div class="ttname"><a href="classEigen_1_1Matrix.html">Eigen::Matrix</a></div><div class="ttdoc">The matrix class, also used for vectors and row-vectors.</div><div class="ttdef"><b>Definition:</b> Matrix.h:182</div></div>
<div class="ttc" id="aclassEigen_1_1PlainObjectBase_html_ac54123f62de4c46a9107ff53890b6116"><div class="ttname"><a href="classEigen_1_1PlainObjectBase.html#ac54123f62de4c46a9107ff53890b6116">Eigen::PlainObjectBase::data</a></div><div class="ttdeci">const Scalar * data() const</div><div class="ttdef"><b>Definition:</b> PlainObjectBase.h:259</div></div>
<div class="ttc" id="aclassEigen_1_1PlainObjectBase_html_acc39eaf7ba22b725c86f1b9b8bb57c3c"><div class="ttname"><a href="classEigen_1_1PlainObjectBase.html#acc39eaf7ba22b725c86f1b9b8bb57c3c">Eigen::PlainObjectBase::setZero</a></div><div class="ttdeci">Derived &amp; setZero(Index size)</div><div class="ttdef"><b>Definition:</b> CwiseNullaryOp.h:564</div></div>
<div class="ttc" id="aclassEigen_1_1SparseMatrix_html"><div class="ttname"><a href="classEigen_1_1SparseMatrix.html">Eigen::SparseMatrix</a></div><div class="ttdoc">A versatible sparse matrix representation.</div><div class="ttdef"><b>Definition:</b> SparseMatrix.h:100</div></div>
<div class="ttc" id="aclassEigen_1_1Triplet_html"><div class="ttname"><a href="classEigen_1_1Triplet.html">Eigen::Triplet</a></div><div class="ttdoc">A small structure to hold a non zero as a triplet (i,j,value).</div><div class="ttdef"><b>Definition:</b> SparseUtil.h:163</div></div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Thu Apr 21 2022 13:07:55 for Eigen by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
